<template>
  <div class="index" style=" font-size: 14px; padding: 20px;">
    <div style="margin-bottom: 20px;"><el-button type="danger" round @click="postlist()">生成导出表</el-button></div>
    <div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="created_at" label="生成时间"> </el-table-column>
        <el-table-column prop="date" label="导出区间">
          <template slot-scope="scope">
            {{scope.row.start_time}} - {{scope.row.end_time}}
          </template>
        </el-table-column>
        <el-table-column prop="date" label="操作">
          <template slot-scope="scope">
            <el-button size="mini" style="primary" @click="handleEdit(scope.$index, scope.row)" v-if="scope.row.status == 20">下载</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background layout="total,prev, pager, next" style="text-align: right; margin: 20px;"
        :current-page="all.page" @current-change="fanye" :page-size="all.page_size" :total="total"></el-pagination>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'waibugongju',
    data() {
      return {
        tableData: [],
        all: {
          page: 1,
          page_size: 20
        },
        total: 0
      }
    },
    created() {
      this.getlist()
    },
    mounted() {

    },
    methods: {
      fanye: function(page) {
        this.all.page = page
        this.getlist()
      },
      handleEdit: function(index, item) {
        this.$prompt('请输入密码', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({
          value
        }) => {
          axios.post(`/api/logistics/order/log`, {
              password: value,
              id:item.id
            })
            .then(response => {
              if (response.data.msg.code == 0) {
                location.href = response.data.data.result_file + '?attname='
              } else {
                vant.Toast(response.data.msg.info);
              }
            })
        })
      },
      getlist: function() {
        axios.get(`/api/logistics/order/list`, {
            params: this.all
          })
          .then(response => {
            if (response.data.msg.code == 0) {
              this.tableData = response.data.data.data
              this.total = response.data.data.total
            } else {
              vant.Toast(response.data.msg.info);
            }
          })
      },
      postlist: function() {
        this.$prompt('请输入密码', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({
          value
        }) => {
          axios.post(`/api/logistics/order/expend`, {
              password: value
            })
            .then(response => {
              if (response.data.msg.code == 0) {
                vant.Toast('操作成功');
              } else {
                vant.Toast(response.data.msg.info);
              }
            })
        })

      },

    }
  }
</script>


<style scoped lang="less">
  /deep/ .el-message {
    font-size: 14px !important;
  }
</style>
